import { createI18n } from "vue-i18n";
import en from "./i18n/en";
import zh_CN from "./i18n/cn";                                                                                               
import ko_KR from "./i18n/ko_KR";                                                                                               


let navLang = navigator.language; //判断当前浏览器使用的语言
// if (navLang == "zh-CN") {
//   navLang = "zh_CN"
// }
// console.log(navLang);
const localLang = navLang === "zh_CN" || navLang === "en" ? navLang : false;
let lang = localStorage.getItem("lang") || localLang || "en"; //如果有缓存，取缓存的语言
// console.log(lang);

const messages = {
  en,
  zh_CN,
  ko_KR
};
const i18n = createI18n({
  locale: lang,
  fallbackLocale: lang,
  messages,
  legacy: false,
  globalInjection: true
});
localStorage.setItem("lang", lang); //最后缓存当前使用的语言

export default i18n;